Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

uptown

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uptown

Simple ways to extend prototypes

  • 0.4.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Uptown

Build Status

Simplify prototypical inheritance. This tries to provide some simple constructs for providing functionality you get with ES6 classes, such as:

  • Constructor functions
  • Static class methods
  • Getter and setter methods

Install

npm install uptown --save

Usage

Use extendify to add the extend method to a class (note: it mutates the original class).

The extend class method takes three options arguments:

  1. Object of instance properites
  2. Object of static methods and properties
  3. Object of getter and setter mutators
var extendify = require('uptown').extendify;

var Original = function() {};

Original.prototype.hello = function(value) {
  return 'Hello, ' + value;
}

extendify(Original);

var SubClass = Original.extend({
  // Specify a constructor for the new class
  constructor: function() {
    // Call parent constructor
    Original.apply(this, arguments);
  },

  hello: function(value) {
    // Add exclamation point
    return Original.prototype.hello.call(this, value + '!')
  }
}, {
  // Specify static methods and properties
  staticMethod: function() {}
}, {
  // Specify getters and setters for the new class
  foo: {
    get: function() {},
    set: function() {}
  }
});

New classes may also be created using the createClass function. The createClass function works just like .extend.

var createClass = require('uptown').createClass;

var Foo = createClass({
  constructor: function() {
    this.foo = 'bar';
  }
});

Keywords

FAQs

Package last updated on 15 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc